package exception;

/**
 * 使用当前类测试异常的抛出
 */
public class Person {
    /*private String name;*/
    private int age;

    public Person() {
    }

    public Person(int age) {
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws IllegalAgeException {
        if (age<0 || age>100){
            //throw new RuntimeException("年龄不合法");

            //throw new Exception("年龄不合法,必须在0到100之间！");

            throw new IllegalAgeException("年龄不合法,必须在0到100之间！");
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}
